package dao.impl;

import bean.Text;
import dao.Dao;
import util.BaseDao;

import java.sql.Date;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

public class DaoImpl implements Dao {
    @Override
    public List<Text> showAll() {
        ArrayList<Text> list= new ArrayList<>();
        String sql="SELECT * FROM t_text t JOIN object o ON t.oid=o.oid JOIN t_write w ON t.wid=w.wid";
        PreparedStatement ps = BaseDao.getPs(sql);
        try {
            ResultSet rs  = ps.executeQuery();
            while (rs.next()){
                int id=rs.getInt(1);
                String name=rs.getString(2);
                String novel=rs.getString(3);
                int dianji=rs.getInt(4);
                Date time=rs.getDate(5);
                int wid=rs.getInt(6);
                int oid=rs.getInt(7);
                String oname=rs.getString(8);
                String wname=rs.getString(9);
                Text text = new Text(id, name, novel, dianji, time, wid, oid, oname, wname);
                list.add(text);
            }
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }
        return list;
    }
}
